package cn.zl.api.dto.user;

import cn.yunbamboos.Model;
import cn.yunbamboos.rest.service.anno.param.ParamType;
import cn.yunbamboos.rest.service.anno.param.enums.Type;
import cn.yunbamboos.rest.service.dto.in.GenericInDTO;
import com.alibaba.fastjson2.JSONObject;
import jakarta.validation.constraints.NotNull;

import java.util.List;
import java.util.function.Consumer;

public class DeleteUserInDTO extends GenericInDTO {

    @NotNull(message = "用户ID列表不能为空")
    @ParamType(path = "list", type = Type.Array, title = "待删除用户ID列表", required = true, typeClass = DeleteUserItem.class)
    private List<DeleteUserItem> list;

    @Override
    public void decode(JSONObject json) {
        super.decode(json);
        this.list = this.getModelList(json, "list", DeleteUserItem.class);
    }

    public void forEach(Consumer<String> consumer) {
        list.forEach(item -> consumer.accept(item.userId));
    }


    public static class DeleteUserItem implements Model {

        @ParamType(path = "user_id", type = Type.String, title = "用户ID", required = true)
        private String userId;

        @Override
        public void decode(JSONObject json) {
            this.userId = json.getString("user_id");
        }

    }
}
